$(function(){
    $('#btn').on('click','button',function(){
        $(this).addClass('active').siblings().removeClass('active')
    })
    var data = 0
    var myChart = echarts.init(document.getElementById('ele'));
    var option = {
        tooltip : {
            formatter: "年用电量: {c} {b}"
        },
        toolbox: {
            feature: {
                restore: {},
                saveAsImage: {}
            }
        },
        series: [
            {
                name: '业务指标',
                type: 'gauge',
                detail: {formatter:['{value}','年用电量'].join('\n')},
                data: [{value: 50, name: 'kW.h'}],
                title:{
                    fontSize:'50',
                    color:'pink',
                    fontStyle:'italic'
                },
                axisLabel:{
                    fontSize:'20',
                    fontWeight:'bold'
                }
            }
        ]
    };

    setInterval(function () {
        $.ajax({
            type: "get",
            method:"get",
            url: "http://192.168.3.8:8080/electricityMeter/findReadData",
            dataType: "json",
            xhrFields: { withCredentials: true},
            crossDomain: true,
            success: function(e) {
                console.log(e.electricityData)
                data = e.electricityData
            },
            error:function(e){
                console.log('error',e)
            }
        });
        option.series[0].data[0].value = data;
        myChart.setOption(option, true);
    },2000);

})